package com.neutech.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.neutech.po.Dept;
import com.neutech.po.Docter1;
import com.neutech.po.User;
import com.neutech.service.DocterService;
import com.neutech.service.UserService;

@Controller
@RequestMapping(value = "/his")
public class UserController {

	@Autowired
	private UserService userservice;
	@RequestMapping("/getUserById")
	public @ResponseBody User getUser(Integer id) {
		User user = userservice.getUser(id);
		return user;
	}
 
	@RequestMapping(value = "/update", method = RequestMethod.GET)
	public  @ResponseBody String update(User user) {
		int result = userservice.getUpdate(user);
		if (result >= 1) {
			return "修改成功";
		} else {
			return "修改失败";
		}
	}
	
	@RequestMapping(value = "/insert", method = RequestMethod.GET)
	public  @ResponseBody User insert(User user) {
		return userservice.insertUser(user);
	}
	
	@RequestMapping(value = "/delete", method = RequestMethod.GET)
	public @ResponseBody String delete(int id) {
		int result = userservice.delete(id);
		if (result >= 1) {
			return "删除成功";
		} else {
			return "删除失败";
		}
	}
	
	@Autowired
	private DocterService docterService;
	@RequestMapping(value="/sdocter",method=RequestMethod.GET)
	 public @ResponseBody Docter1 getdocter(Integer id) {
		 Docter1 doct = docterService.getdocter(id);
		 return doct;
	 }
	
	@RequestMapping(value="/udocter",method=RequestMethod.POST)
	  public @ResponseBody String updatedocterById(Docter1 doct) {
		int result = docterService.updatedocter(doct);
		if(result>=1) {
			return "修改成功";
		}
		    return "修改失败";
	}
	
	@RequestMapping("/ddocter")
	 public @ResponseBody String delUserdoctorById(Integer id) {
		int result = docterService.deledocter(id);
		if(result>=1) {
			return "删除成功";
		}
			return "删除失败"; 
	 }
	
	@RequestMapping(value="/idocter",method=RequestMethod.POST)
	  public @ResponseBody Docter1 insertoctor(Docter1 doct) {
		return docterService.insertdocter(doct);
	}
}
